<?php

namespace Modules\Admin\Policies;

use App\BasePolicy;
use Modules\Admin\Entities\Admin;

class AdminPolicy extends BasePolicy {
    public function viewAny($user) {
        return $user->isAdmin() && $user->hasPermissionTo('show admin');
    }

    public function view($user, Admin $admin) {
        return $user->isAdmin() && $user->hasPermissionTo('show admin');
    }

    public function create($user) {
        return $user->isAdmin() && $user->hasPermissionTo('store admin');
    }

    public function update($user, Admin $admin) {
        // if ($user->isAdmin() && $user->hasPermissionTo('update admin')) {
        //     return true;
        // }
        // if ($user->id == $admin->id) {
        //     return true;
        // }
        // return false;
        return $user->isAdmin() && $user->hasPermissionTo('update admin');
    }

    public function delete($user, Admin $admin) {
        return $user->isAdmin() && $user->hasPermissionTo('delete admin');
    }

    public function restore($user, Admin $admin) {
        return $user->isAdmin() && $user->hasPermissionTo('restore admin');
    }

    public function forceDelete($user, Admin $admin) {
        return $user->isAdmin() && $user->hasPermissionTo('force delete admin');
    }

}
